package com.v.im.imservice.kafka.serializer;

import com.alibaba.fastjson.JSON;
import com.v.im.commonmodule.utils.chat.Message;
import org.apache.kafka.common.serialization.Serializer;

import java.nio.ByteBuffer;
import java.util.Map;

public class MessageSerializer implements Serializer<Message> {

    @Override
    public void configure(Map<String, ?> map, boolean b) {

    }

    @Override
    public byte[] serialize(String s, Message data) {
        if (data == null) {
            return null;
        }
        byte[] objects = JSON.toJSONString(data).getBytes();
        ByteBuffer buffer = ByteBuffer.allocate(objects.length);
        buffer.put(objects);
        return buffer.array();
    }

    @Override
    public void close() {

    }
}
